package com.snfdf.camunda.sendtask;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

@Slf4j
@Component("sendTask")
public class SendTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) {
        log.info("sendTask发送消息");
        RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
        runtimeService.createMessageCorrelation("Message_receive_task_test")
                // 启动接收任务时可以指定需要处理的业务key，发送任务也可动态指定业务key，业务吸必须一致，否则报错，并且接收任务未启动前先启动发送任务也报错
                .processInstanceBusinessKey("message_businessKey")
                .correlate();
    }
}
